layui.use(['laydate','form','table'], function(){
	var laydate = layui.laydate;
	var form = layui.form;
	var table = layui.table;
	var url = window.location.pathname

	/*开始时间*/
	laydate.render({
	  	elem: '#start' //指定元素
	});
	/*结束时间*/
	laydate.render({
	  	elem: '#end' //指定元素
	});
	/*@初始化table*/
	var tableObj = table.render({
	    elem: '#table-list',
	    url: url, //数据接口
	    page: true, //开启分页
	    // where: {u_type:'新客'},
	    cols: [[ //表头
	    	{field: 'visit_log_id', title: '序号'},
	    	{field: 'addtime', title: '拜访时间'},
	    	{field: 'content', title: '拜访记录'},
	    	{title: '操作', width: 100,toolbar: '<div><a class="layui-btn" onclick="xadmin.open(\'拜访记录\',\'/user/visit/details/ids/{{d.visit_log_id}}\')">查看详情</a></div>'},
	    ]]
	});
	/*@查询*/
	form.on('submit(search)',function(data){

		if(data.field.start != '' && data.field.end != ''){
			var startDate = new Date(data.field.start).getTime();
			var endDate = new Date(data.field.end).getTime();
			if(startDate > endDate){
				layer.msg('开始时间不能大于结束时间',{icon: 2})
				return false
			}
		}
		/*重载表格数据*/
		tableObj.reload({
			page: {
                page: 1 //重新从第 1 页开始
            },
            where: data.field
        });
        return false
	})
});